package com.bicon.botu.mall.component.api;

import com.bicon.botu.mall.component.dto.LabelDTO;
import com.bicon.botu.mall.component.service.ILabelService;
import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 标签 通用api
 *
 * @author jingwj
 * @date 2017/12/25 下午 14:49
 */
@RestController
@CrossOrigin
@RequestMapping("/V1.0.0/api/label")
public class LabelApi extends BaseController {

    @Autowired
    private ILabelService iLabelService;

    /**
     * 获取标签库
     *
     * @param labelName  标签名称
     * @return 返回结果集合
     */
    @RequestMapping(value = "/getLabelDetailFromRedis", method = RequestMethod.POST)
    public BaseResult getLabelDetailFromRedis(@RequestParam String labelName, @RequestParam String module) {
        List<LabelDTO> labelList = iLabelService.getLabelDetailFromRedis(labelName, module);
        return sendResult(200, "获取成功", labelList);
    }

    /**
     * 新增标签
     * @param labelName  标签名称
     * @param module  内置模块
     * @return 返回结果集合
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public BaseResult add(@RequestParam String labelName, @RequestParam String module) {
        iLabelService.insert(labelName, module);
        return sendResult(200, "获取成功");
    }
}
